<?php

namespace app\backend\controller;
use app\backend\service\ZhMatchmakerIntroduceService;
use app\backend\model\ZhMatchmakerIntroduce as ZhMatchmakerIntroduceModel;


class ZhMatchmakerIntroduce extends Admin
{
    /*首页数据列表*/
    function index()
    {
        if (!$this->request->isAjax()) {
            return view('index');
        } else {
            $limit           = $this->request->post('limit', 20, 'intval');
            $offset          = $this->request->post('offset', 0, 'intval');
            $where['text']   = $this->request->param('text', '', 'serach_in');

            $page = floor($offset / $limit) + 1;
            $res  = ZhMatchmakerIntroduceService::indexList(formatWhere($where), $limit, $page);
            return json($res);
        }
    }

    public function update(){
        if (!$this->request->isPost()) {
            $id = $this->request->get('id', '', 'serach_in');
            $this->view->assign('info', checkData(\app\backend\model\ZhMatchmakerIntroduce::find($id)));
            return view('update');
        } else {
            $postField = 'text,id,video';
            $data      = $this->request->only(explode(',', $postField), 'post', null);
            $res = \app\backend\model\ZhMatchmakerIntroduce::update($data);
            return json(['status' => '00', 'msg' => '修改成功']);
        }
    }

    /**
     * @return \think\response\Json|\think\response\View
     * @author  lwx
     */
    function add()
    {
        if (!$this->request->isPost()) {
            return view('add');
        } else {
            $postField          = 'text,video';
            $data               = $this->request->only(explode(',', $postField), 'post', null);
            $res                = ZhMatchmakerIntroduceModel::create($data);
            return json(['status' => '00', 'msg' => '添加成功']);
        }
    }
}